# @Time : 2021/4/9 9:41
# @Author : Fioman 
# @Phone : 13149920693
"""
设备的状态类
"""


class OfflineZmcStates(object):
    """
    离线上料的状态类
    """

    def __init__(self):
        self.connectState = -1
        self.online = False
        self.rs = False
        self.run = False
        self.isThrowBoard = True  # 默认是丢板


class CbjZmcStates(object):
    """
    裁切机的状态类
    """

    def __init__(self):
        self.connectState = -1
        self.online = False
        self.rs = False
        self.run = False


class CamZmcStates(object):
    """
    拍照控制器的状态类
    """

    def __init__(self):
        self.connectState = -1
        self.online = False
        self.rs = False
        self.run = False


class CutterZmcStates(object):
    """
    铡刀控制器的状态类.
    """

    def __init__(self):
        self.connectState = -1
        self.online = False
        self.rs = False
        self.run = False


class DeviceStates(object):
    def __init__(self):
        self.camZmcStates = CamZmcStates()
        self.cbjZmcStates = CbjZmcStates()
        self.cutterZmcStates = CutterZmcStates()
        self.mainAlarmInfo = ""  # 主控制器的报警信息
        self.offlineAlarmInfo = ""  # 离线上料控制器的报警信息
        self.offlineAlarmInfoVisible = False
        self.mainAlarmInfoVisible = False
        self.cameraGroupStates = [False, False, False, False]
        self.camZmcIsRs = False
        self.cbjZmcIsRs = False
        self.cutterZmcIsRs = False
        self.camZmcIsRun = False
        self.cbjZmcIsRun = False
        self.cutterZmcIsRun = False
        self.leftCamIsOnline = False
        self.rightCamIsOnline = False
        self.cutterCam1IsOnline = False
        self.cutterCam2IsOnline = False
        self.workStopFlag = True
        # 新增离线上料的状态监控
        self.offlineZmcStates = OfflineZmcStates()
        self.offlineZmcIsRs = False
        self.offlineZmcIsRun = False
        self.offlineOnlineStart = False
        self.shieldStart = [False, False, False, False, False]

    def pack_state_to_dict(self):
        """
        将状态信息封装为字典,好发送给前端
        :return:
        """
        res = {
            "offlineZmcStates": {
                "online": self.offlineZmcStates.online,
                "rs": self.offlineZmcStates.rs,
                "run": self.offlineZmcStates.run,
                "isThrowBoard": self.offlineZmcStates.isThrowBoard
            },
            "camZmcStates": {
                "online": self.camZmcStates.online,
                "rs": self.camZmcStates.rs,
                "run": self.camZmcStates.run
            },
            "cbjZmcStates": {
                "online": self.cbjZmcStates.online,
                "rs": self.cbjZmcStates.rs,
                "run": self.cbjZmcStates.run,
            },
            "cutterZmcStates": {
                "online": self.cutterZmcStates.online,
                "rs": self.cutterZmcStates.rs,
                "run": self.cutterZmcStates.run,
            },
            "mainAlarmInfo": self.mainAlarmInfo,
            "mainAlarmInfoVisible": self.mainAlarmInfoVisible,
            "offlineAlarmInfo": self.offlineAlarmInfo,
            "offlineAlarmInfoVisible": self.offlineAlarmInfoVisible,
            "cameraGroupStates": self.cameraGroupStates,
            "autoState": not self.workStopFlag,
            "offlineOnlineStart": self.offlineOnlineStart,
            "shieldStart": self.shieldStart,
        }
        return res
